import Taro from "@tarojs/taro";
interface requestOption {
  name: string,
  data?: Object,
  method?: any,
  control?: object,
}
export const request = ({ name, data = {}, method = 'GET' }: requestOption) => {
  const url = '' + name; // todo

  return new Promise((res, req) => {
    Taro.request({
      url,
      data,
      header: {'content-type':'application/json'},
      method: method,
      dataType: 'json',
      responseType: 'text',
      success: (result)=>{
        res(result);
      },
      fail: (err)=>{ req(err)},
      complete: ()=>{}
    })
  })
};
export const get = ({name, data = {}, control = {}}) => request({name, data, method: "GET", control});
export const post = ({name, data = {}, control = {}}) => request({name, data, method: "POST", control});
